<template>
	<view class="parent">
		<view class="login-title">账号注册</view>

		<view class="login-input">
			<view class="label"> +86 </view>
			<input class="et" placeholder="请输入手机号" v-model="account" />
		</view>

		<view class="login-input">
			<view class="label"> 验证码 </view>
			<input class="et" placeholder="请输入验证码" v-model="code" />
			<z-button-code :account='account'></z-button-code>
		</view>

		<!-- <view class="phone uni-flex uni-row">
			<view class="label">
				密码
			</view>
			<input class="et" placeholder="请输入密码" v-model="password" password/>
		</view> -->
		<!-- 
		<view class="phone uni-flex uni-row">
			<view class="label">
				邀请码
			</view>
			<input class="et" placeholder="请输入邀请码" v-model="inviteCode"/>
		</view> -->
		
		<z-button text="立即注册" @click.native="onRegister" style="margin-top: 100rpx;"></z-button>
		<z-privacy ref="privacy"></z-privacy>
	</view>
</template>

<script>
import LoginUtil from '../../common/LoginUtil';
	export default {
		data() {
			return {
				account: '',
				code: '',
				password: '',
				inviteCode: '',
			}
		},
		methods: {
			async onRegister() {
				if (!this.$refs.privacy.value()) {
					this.$common.showToast('请勾选隐私政策')
					return
				}
				let param = {loginName: this.account, smsCode: this.code};
				let res = await this.$common.post('/api/login', param);
				if (200 == res.code) {
					LoginUtil.saveToken(res.data)
					this.requestUser()
				} else {
					this.$common.showToast(res.message)
				}
			},
			async requestUser() {
				let res = await this.$common.get('/api/getLoginUser');
				if (200 == res.code) {
					LoginUtil.login(res)
				} else {
					this.$common.showToast(res.message)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.parent {
		background-color: #f5f5f5;
		height: 100vh;
		padding: 0 50rpx;
		
		.login-title {
			color: #222;
			font-size: 50rpx;
			font-weight: bold;
			margin-top: 80rpx;
		}
		
		.login-input {
			display: flex;
			flex-direction: row;
			align-items: center;
			background-color: #ededed;
			border-radius: 10rpx;
			height: 90rpx;
			margin-top: 50rpx;
		
			.label {
				width: 150rpx;
				height: 100%;
				line-height: 90rpx;
				font-size: 36rpx;
				color: #222;
				text-align: center;
				margin: auto 0;
			}
		
			.et {
				height: 100%;
				padding: 0 20rpx;
				font-size: 28rpx;
				flex: 1;
			}
		}
		
	}

	

	
</style>